# Dockerfile - alpine
# https://github.com/openresty/docker-openresty

FROM alpine:latest

MAINTAINER Evan Wies <evan@neomantra.net>

# Install APT dependencies
# Put this before the ARGS to minimize di
RUN apk add --update \
    build-base perl make \
    readline ncurses zlib-dev


# Docker Build Arguments
ENV RESTY_VERSION="1.9.7.4"
ENV RESTY_OPENSSL_VERSION="1.0.2e"
ENV RESTY_PCRE_VERSION="8.38"
ENV RESTY_J="1"
ENV RESTY_CONFIG_OPTIONS="--with-ipv6 --with-pcre-jit --with-http_gunzip_module"

# These are not intended to be user-specified
ENV _RESTY_CONFIG_DEPS="--with-openssl=/tmp/openssl-1.0.2e --with-pcre=/tmp/pcre-8.38"


# Download and untar OpenSSL, PCRE, and OpenResty
WORKDIR /tmp

ADD https://www.openssl.org/source/openssl-${RESTY_OPENSSL_VERSION}.tar.gz /tmp/openssl-$RESTY_OPENSSL_VERSION.tar.gz
RUN tar xzf openssl-$RESTY_OPENSSL_VERSION.tar.gz

ADD https://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$RESTY_PCRE_VERSION.tar.gz /tmp/pcre-$RESTY_PCRE_VERSION.tar.gz
RUN tar xzf pcre-$RESTY_PCRE_VERSION.tar.gz

ADD http://121.40.23.98/download/openresty-$RESTY_VERSION.tar.gz /tmp/openresty-$RESTY_VERSION.tar.gz
RUN tar xzf openresty-$RESTY_VERSION.tar.gz

ADD http://121.40.23.98/myresty.tar.gz /tmp/myresty.tar.gz
RUN tar xzf myresty.tar.gz


# Build OpenResty
WORKDIR /tmp/openresty-$RESTY_VERSION
RUN ./configure -j$RESTY_J $_RESTY_CONFIG_DEPS $RESTY_CONFIG_OPTIONS && \
    make -j$RESTY_J && \
    make -j$RESTY_J install


RUN cp -f /tmp/nginx.conf /usr/local/openresty/nginx/conf/
RUN cp -f /tmp/resty/*.* /usr/local/openresty/lualib/resty/
RUN cp -rf /tmp/lua/ /usr/local/openresty/nginx/
RUN mkdir /usr/local/openresty/nginx/cache_temp

# Cleanup
WORKDIR /tmp
RUN rm -rf *
EXPOSE 80
CMD ["/usr/local/openresty/nginx/sbin/nginx", "-g", "daemon off;"]